package com.py.pythink.controller;

import com.py.pythink.bo.UserBo;
import com.py.pythink.config.SystemConfig;
import com.py.pythink.service.intf.UserService;
import com.py.pythink.vo.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/user/")
@CrossOrigin
@Api(value = "",tags = "用户登录注册相关操作")
public class UserController {
    @Autowired
    private UserService service;

    //校检
    @GetMapping("checkphone.do")
    public R check(String phone){
        System.err.println("检查手机号能否注册");
        return service.checkPhone(phone);
    }

    //校检
    @GetMapping("checktoken.do")
    public R checktoken(HttpServletRequest request){
        return service.checkToken(request.getHeader(SystemConfig.USER_TOKEN));
    }
    @PostMapping("save.do")
    public R save(@RequestBody UserBo bo, HttpServletRequest request){
        return service.register(bo,request.getRemoteAddr());
    }
    @PostMapping("login.do")
    public R login(@RequestBody UserBo bo,HttpServletRequest request){
        return service.login(bo,request.getRemoteAddr());
    }
    @PostMapping("logincode.do")
    public R loginCode(@RequestBody UserBo bo,HttpServletRequest request){
        return service.loginCode(bo,request.getRemoteAddr());
    }
    @GetMapping("loginout.do")
    public R loginOut(HttpServletRequest request){
        return service.loginOut(request.getHeader(SystemConfig.USER_TOKEN),request.getRemoteAddr());
    }
}
